const Sequelize = require('sequelize');
const configs = require('./config');
var sequelize = new Sequelize(configs.db.basename,configs.db.user, configs.db.pass, {
    host: configs.db.host,
    dialect: 'mysql',
    pool: {
        max: 5,
        min: 0,
        idle: 30000
    },
    define: {
        timestamps: false
    }
});
// console.log(dbcofig);
  // 连接数据库
  sequelize
  .authenticate()
  .then(() => {
    console.log('数据库连接成功.');
  })
  .catch(err => {
    console.error('数据库连接失败:', err);
  });
// 数据模型
  const contents = sequelize.define('contents',{
    id:{
      type: Sequelize.INTEGER(10),
      primaryKey: true,
      autoIncrement:true
    },
    nid:Sequelize.INTEGER,
    contents:Sequelize.TEXT
  },{timestamps: false});

  const user = sequelize.define('user',{
    id:{
      type: Sequelize.INTEGER(10),
      primaryKey: true,
      autoIncrement:true
    },
    username:Sequelize.STRING,
    nick:Sequelize.STRING,
    password:Sequelize.STRING,
    wxid:Sequelize.STRING,
    status:Sequelize.INTEGER,
    head_pic:Sequelize.STRING,
    last_login:Sequelize.INTEGER(11),
  },{timestamps: false,freezeTableName:true});

  const notes = sequelize.define('notes',{
    id:{
      type: Sequelize.INTEGER(10),
      primaryKey: true,
      autoIncrement:true
    },
    uid:Sequelize.INTEGER(10),
    title:Sequelize.STRING,
    uptime:Sequelize.INTEGER(10),
    status:Sequelize.INTEGER(10),
    descs:Sequelize.TEXT,
  },{timestamps: false})





module.exports = {
   db:sequelize,
   user:user,
   contents:contents,
   notes:notes
};
